﻿using System.IO;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Markup;
using System.Xml;
using CustomControl;
using GalaSoft.MvvmLight.Messaging;
using TeacherLeftHand.Model;
using TeacherLeftHand.Util;
using TeacherLeftHand.ViewModel;

namespace TeacherLeftHand.View
{
    /// <summary>
    /// Interaction logic for TeachingMethodView.xaml
    /// </summary>
    public partial class TeachingMethodView
    {
        public TeachingMethodView()
        {
            InitializeComponent();

            Loaded += (s,e)=> DataContext = ViewModelLocator.TeachingMethodStatic;

            Messenger.Default.Register<string>(this,"SelectedTMContent", content =>
                                                                     {
                                                                         var rtb = new RichTextEditor();
                                                                         if (!string.IsNullOrEmpty(content))
                                                                         {
                                                                             rtb = (RichTextEditor)
                                                                                       XamlReader.Load(
                                                                                           new XmlTextReader(
                                                                                               new StringReader(
                                                                                                   content)));
                                                                             // ContextMenuService.SetIsEnabled(rtb, false);

                                                                         }
                                                                         rtbContent.Document =
                                                                                 (FlowDocument)Utility.CloneElement(rtb.Document);
                                                                     });

        }
       
    }
}
